﻿////////////////////////////////////////////////////////////
//  Модуль поддержки сохранения определений в Silverlight (реализация)
//  Василий Кудрявцев
//  06 января  2009 года
//

#light

namespace SilverLightFSharp

module SilverlightIO

open Fp
open FpCore
open System.IO
open System.IO.IsolatedStorage

let SaveDefinitions()  = 
   let store = IsolatedStorageFile.GetUserStoreForApplication();
   let stream = new IsolatedStorageFileStream("fp.def", FileMode.Create, store);   
   let writer = new StreamWriter(stream) 
   let mutable enumerator = Fp.FpCore.defs.GetEnumerator();
   while enumerator.MoveNext()
    do
    writer.Write(sprintf "Def %s = %s\n" enumerator.Current.Key (string_of_fct enumerator.Current.Value)) 
    done
   writer.Flush();
   writer.Close();
   stream.Close();
   store.Dispose();

    
let LoadDefinitions() =
 let store = IsolatedStorageFile.GetUserStoreForApplication();
 let stream = new IsolatedStorageFileStream("fp.def", FileMode.OpenOrCreate, store);   
 let reader = new StreamReader(stream) 
 while reader.EndOfStream = false
  do
   (reader.ReadLine()^"\n") |> Fp.FpInterperter.exe |> ignore
 done
 reader.Close();
 stream.Close();
 store.Dispose(); 
 

